package com.it.controller;

import com.alibaba.fastjson.JSONObject;
import com.it.domain.Admin;
import com.it.service.AdminService;
import com.it.common.CONSTS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RequestMapping("/admin")
@RestController
public class AdminController {

    @Autowired
    private AdminService adminService;

    @PostMapping("/login")
    public Object Login(@RequestBody Admin admin){
        JSONObject jsonobject = new JSONObject();
        String username = admin.getUsername();
        String password = admin.getPassword();
        boolean flag = adminService.VerifyAdmin(username,password);
        if(flag){
            jsonobject.put(CONSTS.CODE,200);
            jsonobject.put(CONSTS.MSG,"登录成功");
            jsonobject.put(CONSTS.NAME,username);
        }
        else{
            jsonobject.put(CONSTS.CODE,400);
            jsonobject.put(CONSTS.MSG,"登录失败,请重新输入");
        }
        return jsonobject;
    }
}
